package com.allenkerr.service.impl;

import com.allenkerr.mapper.PersonMapper;
import com.allenkerr.model.Person;
import com.allenkerr.service.PersonService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by 小柯(Allen Kerr) on 17.6.18 23:54.
 */
@Service
public class PersonServiceImpl implements PersonService {

    @Autowired
    private PersonMapper personMapper;

    @Override
    public List<Person> findAll() {
        return personMapper.findAll();
    }

    @Override
    public Person findById(Integer id) {
        Person person = personMapper.findById(id);
        return person;
    }

    @Override
    public Person findByName(String name) {
        Person person = personMapper.findByName(name);
        return person;
    }

//    /**
//     * 分页查询
//     * @param pageNum
//     * @param pageSize
//     * @return
//     */
//    @Override
//    public List<Person> findByPage(Integer pageNum, Integer pageSize) {
//        //使用 pageHelper 实现分页
//        PageHelper.startPage(pageNum, pageSize);
//        //查询数据
//        return personMapper.findAll();
//    }

    @Transactional  //开启事务
    @Override
    public void saveOne(Person person) {
        personMapper.saveOne(person);
    }
}
